/* 引入less */
/* 重置样式 */
require('../css/commCss/normalize.css')
/* 重置样式补充 */
require('../css/commCss/reset.css')
/* 公共样式 */
require('../css/commCss/property.css')
/* 公共属性 */
require('../css/commCss/basic.less')
/* 字体图标 */
require('../fonts/iconfont.css')
/* 当前页面 */
require('../css/course.less')

const util = require('../util/util')
/* 引入weui */
require('weui');
const weui = require('weui.js');

/* 引入axios */
const axios = require('axios');

document.addEventListener('DOMContentLoaded', function () {

    //顶部导航栏
    util.sportsTopNav('course')
    //底部导航栏
    util.utilBottomNav('running','body')

    /* 渲染数据 */
  axios.get("http://139.9.177.51:8099/sports/allcourse").then(function (res) {
    
    let data = res.data.data;
    console.log(data);
    let newCourse = data.filter(function(item){
      return item.latest === 1
    });
    let commonCourse = data.filter(function(item){
      return item.latest === 0
    });

    /* 最新课程 */
    document.querySelector("#newCourseImg").src = "http://139.9.177.51:8099" + newCourse[0].imgurl;
    document.querySelector("#newCourse").textContent = newCourse[0].name;
    document.querySelector("#courseDesc").textContent = newCourse[0].desc;

    /* 最新课程自定义属性 */
    document.querySelector(".course-video").dataset.cid = newCourse[0].courseId;

    /* 普通课程 */
    let commonCourseArr = commonCourse.map(function(item){
      return `
      <div class="pectoral" data-cid="${item.courseId}">
        <img src="http://139.9.177.51:8099${item.imgurl}" alt="">
        <p>${item.name}</p>
        <span>${item.desc}</span>
      </div>
      `
    })

    document.querySelector("#detailedCourse").innerHTML = commonCourseArr.join("");
  
  })

  /* A-B页面传参 */
  /* 最新课程 */
  document.querySelector(".course-video").addEventListener("click",function(){
    //获取自定义属性
    let cid = this.dataset.cid;
    //存入会话存储
    sessionStorage.cid = cid;
    //跳转
    location.href = "./courseIntroduction.html"
  })

  /* 普通课程 */
  document.querySelector("#detailedCourse").addEventListener("click",function(event){
    //获取自定义属性
    let cid = event.target.closest('div').dataset.cid;
    //存入会话存储
    sessionStorage.cid = cid;
    //跳转
    location.href = "./courseIntroduction.html"
  })

})